import * as utils from '@/util/utils';
import config from '@/config';
import router from '../router';
import comps from '@/components/common';
import { Loading } from 'element-ui';
// import { isLogin } from 'services/common/manager';
// import { addFavicon } from '@/common/util';

export default function(Vue) {
	for (const key in utils) {
		if (utils.hasOwnProperty(key)) {
			Vue.prototype['$' + key] = utils[key];
			// console.log(Vue.prototype['$' + key])
		}
	}
	installGlobalComponents(Vue);
	initMain(Vue);
}

export function installGlobalComponents(Vue) {
	for (const comp in comps) {
		if (comps.hasOwnProperty(comp)) {
			const item = comps[comp];
			if (item.name) {
				Vue.use(item);
				// Vue.component(item.name, item)
			} else {
				Vue.component(comp, item);
			}
		}
	}
}

function initMain(Vue) {
	Vue.prototype.$config = config; //全局配置文件
	Vue.prototype.$loading = Loading.service;
	Vue.mixin({
		mounted() {
			this.$nextTick(() => {
				let node = document.querySelectorAll('input');
				node.forEach((item) => {
					item.setAttribute('autocomplete', 'off');
				});
			});
		},
		methods: {}
	});
	Vue.filter('formatTime', (val) => {
		if (val) {
			return val.substring(0, 10);
		}
		return val;
	});
}
